<include file="public@header"/>
<style type="text/css">
    input[type=number] {
        -moz-appearance:textfield;
    }
    input[type=number]::-webkit-inner-spin-button,
    input[type=number]::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
</style>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
               style="width: 200px;" title="文件名称">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
        <a href="javascript:upload_one('图片上传','#file-{id}');">替换</a>
        <a href="javascript:$('#saved-file{id}').remove();">移除</a>
    </li>
</script>
</head>

<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Student/index')}">学生列表</a></li>
        <!--<li><a href="{:url('Student/add')}">添加学生</a></li>-->
        <!--<li><a href="{:url('Student/add')}">添加学生</a></li>-->
    </ul>

    <form class="well form-inline margin-top-20 row" method="post" action="{:url('Student/index')}">
        <label class="col-sm-6 col-md-4 form-group" style="margin-bottom:15px">
            学生姓名:
            <input type="text" class="form-control" name="name"
                   value="{$param.name|default=''}" placeholder="按学生姓名搜索">
        </label>
        <label class="col-sm-6 col-md-4 form-group" style="margin-bottom:15px">
             学生学号:
            <input type="text" class="form-control" name="code"
                   value="{$param.code|default=''}" placeholder="按学号/老学号搜索">
        </label>
        <label class="col-sm-6 col-md-4 form-group" style="margin-bottom:15px">
            家长姓名:
            <input type="text" class="form-control" name="parent_name"
                   value="{$param.parent_name|default=''}" placeholder="按家长姓名搜索">
        </label>
        <label class="col-sm-6 col-md-4 form-group" style="margin-bottom:15px">
            家长手机:
            <input type="number" class="form-control" name="mobile" maxlength="11"
                   value="{$param.mobile|default=''}" placeholder="按家长手机号搜索">
        </label>
        <label class="col-md-4 col-sm-6  form-group" style="margin-bottom:15px">
            所属校区:
            <select class="form-control" name="school_id" id="school_id">
                <option value='0'>全部</option>
                <notempty name="school_data">
                    <volist name="school_data" id="vo">
                        <if condition="isset($param.school_id) && $param.school_id == $vo.id">
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else/>
                            <option value="{$vo.id}">{$vo.name}</option>
                        </if>
                    </volist>
                </notempty>
            </select>
        </label>
        <label class="col-md-4 col-sm-6  form-group" style="margin-bottom:15px">
            课程：
            <select class="form-control" name="course_id" id="course_id">
                <option value="0">全部</option>
                <notempty name="course_data">
                    <volist name="course_data" id="vo">
                        <if condition="isset($param.course_id) && $param.course_id == $vo.id">
                            <option value="{$vo.id}" selected>{$vo.course_name}</option>
                            <else/>
                            <option value="{$vo.id}">{$vo.course_name}</option>
                        </if>
                    </volist>
                </notempty>
            </select>
        </label>
        <label class="col-md-4 col-sm-6  form-group" id="class_id1">
            班级：
            <select class="form-control" name="class_id" id="class_id">
                <option value="0">全部</option>
                <notempty name="data_class">
                    <volist name="data_class" id="vo">
                        <if condition="isset($param.class_id) && $param.class_id == $vo.cid">
                            <option value="{$vo.cid}" selected>{$vo.cname}</option>
                            <else/>
                            <option value="{$vo.cid}">{$vo.cname}</option>
                        </if>
                    </volist>
                </notempty>
            </select>
        </label>
        <label class="col-md-2 col-sm-5  form-group" id="class_id11">
            状态：
            <select class="form-control" name="is_read" id="class_id13">
                         <option value="0">全部</option>
                        <if condition="isset($param.is_read) && $param.is_read ==1">
                                  <option value="1" selected>在读</option>
                            <else/>
                            <option value="1" >在读</option>
                        </if>
                <if condition="isset($param.is_read) && $param.is_read ==2">
                    <option value="2" selected>未在读</option>
                    <else/>
                    <option value="2" >未在读</option>
                </if>

            </select>
        </label>
        <label class="col-md-2 col-sm-5  form-group" id="class_id111">
            信息来源：
            <select class="form-control" name="information_sources_type" id="class_id113">
                <option value="0">全部</option>
                <if condition="isset($param.information_sources_type) && $param.information_sources_type ==1">
                    <option value="1" selected>学校推荐</option>
                    <else/>
                    <option value="1" >学校推荐</option>
                </if>

                </if><if condition="isset($param.information_sources_type) && $param.information_sources_type ==2">
                <option value="2" selected>老师推荐</option>
                <else/>
                <option value="2" >老师推荐</option>
            </if><if condition="isset($param.information_sources_type) && $param.information_sources_type ==3">
                <option value="3" selected>学校官方</option>
                <else/>
                <option value="3" >学校官方</option>
            </if><if condition="isset($param.information_sources_type) && $param.information_sources_type ==4">
                <option value="4" selected>学校微信</option>
                <else/>
                <option value="4" >学校微信</option>
            </if><if condition="isset($param.information_sources_type) && $param.information_sources_type ==5">
                <option value="5" selected>新闻媒体</option>
                <else/>
                <option value="5" >新闻媒体</option>
            </if><if condition="isset($param.information_sources_type) && $param.information_sources_type ==6">
                <option value="6" selected>信箱广告</option>
                <else/>
                <option value="6" >信箱广告</option>
            </if>
            <if condition="isset($param.information_sources_type) && $param.information_sources_type ==7">
                <option value="7" selected>同学推荐</option>
                <else/>
                <option value="7" >同学推荐</option>
              </if>
                <if condition="isset($param.information_sources_type) && $param.information_sources_type ==8">
                    <option value="8" selected>朋友介绍</option>
                    <else/>
                    <option value="8" >朋友介绍</option>
                </if>
                <if condition="isset($param.information_sources_type) && $param.information_sources_type ==9">
                    <option value="9" selected>其他</option>
                    <else/>
                    <option value="9" >其他</option>
                </if>
            </select>
        </label>
        <label class="col-sm-7 col-md-4 form-group" >

        <input type="submit" class="btn btn-primary" value="搜索"/>
        <a class="btn btn-danger" href="{:url('Student/index')}">清空</a>
        </label>
    </form>
    <br>
    <br>
    <form class="col-sm-6 col-md-4 form-group" style="float:right;margin-top:-114px;" method="post" action="{:url('Student/excel')}"  enctype="multipart/form-data">
        <label>
            <div style="display:inline-block;width:200px;">
                <input type="file" name="pic" style="opacity: 0;margin-left:10px;width:10px;">
                <span  class="btn btn-primary"  title="点击这里选择上传文件" style="position: absolute;z-index:99;top:0px;">选择文件</span>
                <span  id="choose_file" style="position: absolute;z-index:99;top:5px;left:100px;width:100px;white-space:nowrap;overflow:hidden; text-overflow:ellipsis;">未选择任何文件</span>
            </div>
            <button type="submit" id="excelSubmit" class="btn btn-primary js-ajax-submit">导入 </button>
        </label>
        <if condition="isset($session)">
            <div id="sessionBox" style="display: none;padding:0 15px 15px 15px;margin:15px;">
                <foreach name="session" item="vo">
                    <p>
                        {$vo}
                    </p>
                </foreach>
                <a href="{:url('Student/clean')}" style="float:right;">清除错误提示</a>
            </div>
        </if>
    </form>
    <form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('Student/delete')}" data-subcheck="true" data-msg="您确定删除吗？">
                批量删除
            </button>
            <button class="btn btn-sm btn-primary">
                <a href="{:url('Student/excel_export')}" style="color:#fff;">导出</a>
            </button>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>

                <th>编号</th>
                <th>学号</th>
                <th>老学号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年级</th>
                <th>生日</th>
                <th>所在学校</th>
                <th>家长姓名</th>
                <th>家长手机</th>
                <th>联系地址</th>
                <th>信息来源</th>
                <th>助学金</th>
                <th>操作</th>
            </tr>
            </thead>
            <notempty name="students">
                <foreach name="students" item="vo">
                    <tr>
                        <td>
                            <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                                   value="{$vo.id}" title="ID:{$vo.id}">
                        </td>
                        <td>{$vo.id}</td>
                        <td>{$vo.code}</td>
                        <td>{$vo.old_code}</td>
                        <td>{$vo.name}</td>
                        <if condition="$vo.gender eq 1">
                            <td>男</td>
                        <elseif condition="$vo.gender eq 2"/>
                            <td>女</td>
                        <else/>
                            <td>保密</td>
                        </if>
                        <td>
                                <if condition="$vo.grade eq 1">
                                    一年级
                                </if>
                                <if  condition="$vo.grade eq 2">
                                    二年级
                                </if>
                                <if  condition="$vo.grade eq 3">
                                    三年级
                                </if>
                                <if  condition="$vo.grade eq 4">
                                   四年级
                                </if>
                                <if  condition="$vo.grade eq 5">
                                   五年级
                                </if>
                                <if  condition="$vo.grade eq 6">
                                    六年级
                                </if>
                                <if  condition="$vo.grade eq 7">
                                    七年级
                                </if>
                                <if  condition="$vo.grade eq 8">
                                    八年级
                                </if>
                                <if  condition="$vo.grade eq 9">
                                    九年级
                                </if>
                                <if  condition="$vo.grade eq 10">
                                    高一

                                </if>
                                <if  condition="$vo.grade eq 11">
                                    高二

                                </if>
                                <if  condition="$vo.grade eq 12">
                                    高三
                                </if>

                        </td>
                        <if condition="!empty($vo.birthday)">
                            <td>{$vo.birthday|date='Y-m-d',###}</td>
                        <else/>
                            <td></td>
                        </if>
                        <td>{$vo.school_name}</td>
                        <td>{$vo.realname}</td>
                        <td>{$vo.mobile}</td>
                        <td>{$vo.address}</td>
                        <td>
                           {$vo.information_sources}
                        </td>
                        <td>{$vo.award_type}</td>
                        </if>
                        <td>
                            <a href="{:url('Student/edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a> |
                            <a href="{:url('Student/view',array('id'=>$vo['id']))}">详情</a> |

                            <a href="{:url('Student/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                        </td>
                    </tr>
                </foreach>
            </notempty>
            <tr>
                {$count}/{$total}
            </tr>
        </table>
        <div class="pagination">{$page|default=''}</div>
    </form>
</div>

<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/layer/layer.js"></script>

<script>
    function upload()
    {
        filename=$("#file-undefined-preview").attr('href');
        $.ajax({
            url:"{:url('Student/excel')}",
            type:'get',
            dataType:'json',
            data:{'filename':filename},
            success:function(data)
            {
                layer.msg('导入成功', {time:1000,icon: 6});
                location.reload();
            },
            error:function()
            {
                layer.msg('导入失败', {time:1000,icon: 5});
                location.reload();
            }
        })
    }

    $(document).ready(function () {
        var $show = $('#choose_file');
        var $val = $('#choose_file').siblings('input');
        $val.change(function (){
            if($val.val()==''){
                $show.text('未选择任何文件');
                $show.attr('title',"");
            }else {
                var arr=$val.val().split('\\');
                $show.text(arr[arr.length-1]);
                $show.attr('title',arr[arr.length-1]);
            }
        })

        if($('#sessionBox').find('p').length!=0){
            layer.open({
                type: 1,
//                btn: ['清除提醒'],
                title: '未上传成功的数据提示',
                content: $('#sessionBox'),

            })

        }


        $('#school_id').on('change',function () {
            var sid = $(this).val();
            $course_id=$("#course_id option:selected").val();

            //如果课程和校区都是空的，就是删除班级的
            if(sid == 0 && $course_id==0){
                $('#class_id').empty();
                $('#class_id').html();
                return false;
            }
            $.ajax({
                url:"{:url('classes/Classes/ajax1_class')}",
                type:'post',
                dataType:'json',
                data:{"school_id":sid,'course_id':$course_id},
                success:function(jsonData){
                    $('#class_id').empty();
                    jsonData=jQuery.parseJSON(jsonData);
                    console.log(jsonData);
                    if(jsonData.code == 1){
                        $("<option value=0>全选</option>").appendTo($("#class_id"));
                        for(var i in jsonData.data){

                            html = '<option  value=\"'+jsonData.data[i].id+'\" >'+jsonData.data[i].name+"</option>";
                            $('#class_id').append(html);
                        }
                    }else{
                        html = '<option  value=0 >没有此班级</option>';
                        $('#class_id').append(html);
                    }
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
                }
            });
        });

        $('#course_id').on('change',function () {
            var $course_id = $(this).val();
            sid=$("#school_id option:selected").val();

            //如果课程和校区都是空的，就是删除班级的
            if(sid == 0 && $course_id==0){
                $('#class_id').empty();
                $('#class_id').html();
                return false;
            }


            $.ajax({
                url:"{:url('classes/Classes/ajax1_class')}",
                type:'post',
                dataType:'json',
                data:{"school_id":sid,'course_id':$course_id},
                success:function(jsonData){
                    $('#class_id').empty();
                    $("<option value=0>全选</option>").appendTo($("#class_id"));
                    if(jsonData.code == 1){
                        for(var i in jsonData.data){
                            html = '<option  value=\"'+jsonData.data[i].id+'\" >'+jsonData.data[i].name+"</option>";
                            $('#class_id').append(html);
                        }
                    }else{
                        html = '<option  value=0 >没有此班级</option>';
                        $('#class_id').append(html);
                    }
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
                }
            });
        });

        $(".teacher").mouseover(function(e)
        {
            type=$(this).attr('attr_type');
            tid=$(this).attr('attr_id');
            var tooltip="<div id='tooltip'></div>";
            $("body").append(tooltip);
            $("#tooltip").css({
                'top': (e.pageY)+'px',
                'left': (e.pageX)+'px',
                'position':'absolute',
//			'width':100,
//			'height':20,
//			'background':'blue',
//			'z-index':2000,
            }).show('fast');
            public();

        }).mouseout(function()
        {
            $("#tooltip").remove();
        })
        $(".student_student").mouseover(function(e)
        {
            type=$(this).attr('attr_type');
            tid=$(this).attr('attr_id');
            var tooltip="<div id='tooltip'></div>";
            $("body").append(tooltip);
            $("#tooltip").css({
                'top': (e.pageY)+'px',
                'left': (e.pageX)+'px',
                'position':'absolute',
//			'width':100,
//			'height':20,
//			'background':'blue',
//			'z-index':2000,
            }).show('fast');
            public();

        }).mouseout(function()
        {
            $("#tooltip").remove();
        })
        $(".other").mouseover(function(e)
        {
            type=$(this).attr('attr_type');
            tid=$(this).attr('attr_id');
            var tooltip="<div id='tooltip'></div>";
            $("body").append(tooltip);
            $("#tooltip").css({
                'top': (e.pageY)+'px',
                'left': (e.pageX)+'px',
                'position':'absolute',
//			'width':100,
//			'height':20,
//			'background':'blue',
//			'z-index':2000,
            }).show('fast');
            public();

        }).mouseout(function()
        {
            $("#tooltip").remove();
        })
        $(".friend").mouseover(function(e)
        {
            type=$(this).attr('attr_type');
            tid=$(this).attr('attr_id');
            var tooltip="<div id='tooltip'></div>";
            $("body").append(tooltip);
            $("#tooltip").css({
                'top': (e.pageY)+'px',
                'left': (e.pageX)+'px',
                'position':'absolute',
//			'width':100,
//			'height':20,
//			'background':'blue',
//			'z-index':2000,
            }).show('fast');
            public();

        }).mouseout(function()
        {
            $("#tooltip").remove();
        })
        function public(e)
        {

            $.ajax({
                url:"{:url('student/student/ajax_all')}",
                type:'post',
                dataType:'json',
                data:{"student_id":tid,'type':type},
                success:function(jsonData){
                    jsonData=jQuery.parseJSON(jsonData);
                    console.log(jsonData);
                    if(jsonData.code == 1){
                        html = jsonData.data;
                        $('#tooltip').append(html);
                    }else{
                        html = '不存在';
                        $('#tooltip').append(html);
                    }
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
                }
            });
        }
    })
</script>
</body>
